//
//  constructor_member_init.hpp
//  learnC++
//
//  Created by apple on 2018/6/2.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef constructor_member_init_hpp
#define constructor_member_init_hpp

#include <stdio.h>
#include <iostream>
#include <cstdint>
class MemberInit {
private:
    //const  初始化const常量 但不能分配给它们！
    const int m_const;
    const int m_array[5];
    int m_value1;
    double m_value2;
    char m_value3;
    
    //综合：类初始化先看构造函数后面的冒号的参数，有就按该值初始化成员，没有也分配内存成员，然后走构造函数
public:
//    使用成员初始值设定项列表来初始化您的类成员变量而不是赋值
    MemberInit(int value1, double value2=10.3, char value3='c')
    : m_const{5},m_array{ 1, 2, 3, 4, 5},m_value1{value1}, m_value2{value2}, m_value3{value3}  {
    }

    void print()
    {
        std::cout << "MemberInit(" << m_const << ", " << m_value1 << ", " << m_value2 << ", " << m_value3 << ")\n";
    }
};

class RGBA{
    
private:
    std::uint8_t m_red;
    std::uint8_t m_green;
    std::uint8_t m_blue;
    std::uint8_t m_alpha;

public:
    RGBA(std::uint8_t red = 0,std::uint8_t green = 0,std::uint8_t blue = 0,std::uint8_t alpha = 255)
        :m_red(red),m_green(green),m_blue(blue),m_alpha(alpha)
    {
        
    }
    
    void print()
    {
        std::cout << "r=" << static_cast<int>(m_red) <<
        " g=" << static_cast<int>(m_green) <<
        " b=" << static_cast<int>(m_blue) <<
        " a=" << static_cast<int>(m_alpha) << '\n';
    }
};


class A
{
public:
    A(int x) { std::cout << "A " << x << "\n"; }
};

class B
{
private:
    A m_a;
public:
    B(int y)
    : m_a(y-1) // call A(int) constructor to initialize member m_a
    {
        std::cout << "B " << y << "\n";
    }
    
};

class C : public A{
    
    int m_x;
    int m_y;
    
public:
    C(int a):A(a),m_x(a),m_y(a){
        
    }
};

#endif /* constructor_member_init_hpp */
